/*
 * Created on 2005-6-8
 *
 */
package com.hd123.rumba.util;

import java.math.BigDecimal;

/**
 * @author caili
 */
public class CalculationTest {

  public static void main(String[] args) {
    System.out.println("01234567".substring(3));
    System.out.println("01234567".substring(3, 6));

    TRQuantity q;
    print("qtyToStr", q = Calculation.qtyToStr(new BigDecimal(0), new BigDecimal(0)));
    print("strToQty", Calculation.strToQty(q.getQtyStr(), q.getQpc()));
    print("qtyToStr", q = Calculation.qtyToStr(new BigDecimal(10), new BigDecimal(0)));
    print("strToQty", Calculation.strToQty(q.getQtyStr(), q.getQpc()));
    print("qtyToStr", q = Calculation.qtyToStr(new BigDecimal(10), new BigDecimal(1)));
    print("strToQty", Calculation.strToQty(q.getQtyStr(), q.getQpc()));
    print("qtyToStr", q = Calculation.qtyToStr(new BigDecimal(10), new BigDecimal(2)));
    print("strToQty", Calculation.strToQty(q.getQtyStr(), q.getQpc()));
    print("qtyToStr", q = Calculation.qtyToStr(new BigDecimal(10), new BigDecimal(3)));
    print("strToQty", Calculation.strToQty(q.getQtyStr(), q.getQpc()));
    print("qtyToStr", q = Calculation.qtyToStr(new BigDecimal(-10), new BigDecimal(0)));
    print("strToQty", Calculation.strToQty(q.getQtyStr(), q.getQpc()));
    print("qtyToStr", q = Calculation.qtyToStr(new BigDecimal(-10), new BigDecimal(1)));
    print("strToQty", Calculation.strToQty(q.getQtyStr(), q.getQpc()));
    print("qtyToStr", q = Calculation.qtyToStr(new BigDecimal(-10), new BigDecimal(2)));
    print("strToQty", Calculation.strToQty(q.getQtyStr(), q.getQpc()));
    print("qtyToStr", q = Calculation.qtyToStr(new BigDecimal(-10), new BigDecimal(3)));
    print("strToQty", Calculation.strToQty(q.getQtyStr(), q.getQpc()));
    print("strToQty", Calculation.strToQty("2.1", new BigDecimal(3)));
    print("strToQty", Calculation.strToQty("-2.2", new BigDecimal(3)));
    print("strToQty", Calculation.strToQty("2+2.1", new BigDecimal(3)));
    print("strToQty", Calculation.strToQty("-(2+2.1)", new BigDecimal(3)));

    // int scale = 2;
    BigDecimal[] totals = {
        new BigDecimal(10), new BigDecimal(10.1) };
    BigDecimal[] factors = {
        new BigDecimal(0.1), new BigDecimal(0.2), new BigDecimal(0.5), new BigDecimal(0.2),
        new BigDecimal(0.2), new BigDecimal(0.2), new BigDecimal(0.52), new BigDecimal(0.12),
        new BigDecimal(0.2), new BigDecimal(0.2), new BigDecimal(0.52), new BigDecimal(0.12)};
    BigDecimal[][] results = null;
    StopWatch sw = new StopWatch();
    sw.start();
    for (int i = 0; i < 1000; ++i)
      results = Calculation.apportion(totals, factors, 2);
    sw.stop();
    System.out.println("time used for 1000 calc: " + sw.getTime());
    for (int i = 0; i < totals.length; ++i) {
      System.out.print("total=" + totals[i]);
      for (int j = 0; j < factors.length; ++j) {
        System.out.print(" factor=" + factors[j] + " portion=" + results[i][j]);
      }
      System.out.println();
    }
  }

  public static void print(String s, TRQuantity qty) {
    System.out.println(s + ": qpc=" + qty.getQpc() + " qty=" + qty.getQty() + " qtyStr="
        + qty.getQtyStr());
  }
}
